

import instance from "../../utils/axios"

// 文章频道列表
function getChannelList() {
    return instance({
        url: '/v1_0/channels',
        method: "get"
    })
}

// 文章列表
function getArticleList({ channel_id, timestamp }) {
    return instance({
        url: '/v1_0/articles',
        method: "get",
        params: {
            with_top: 1,
            channel_id,
            timestamp
        }
    })
}

// 文章详细信息
function getArticleInfo(id) {
    return instance({
        url: `/v1_0/articles/${id}`,
        method: "get"
    })
}

// 关注接口
function addFlowing(target) {
    return instance({
        url: `/v1_0/user/followings`,
        method: "post",
        data: { target }
    })
}

//取消关注
function delFlowing(target) {
    return instance({
        url: `/v1_0/user/followings/${target}`,
        method: "delete",

    })
}

// 点赞
function addLikings(target) {
    return instance({
        url: `/v1_0/article/likings`,
        method: "post",
        data: { target }
    })
}

//取消点赞
function delLikings(target) {
    return instance({
        url: `/v1_0/article/likings/${target}`,
        method: "delete",

    })
}

function addDisLikes(target) {
    return instance({
        url: `/v1_0/article/dislikes`,
        method: 'post',
        data: { target }
    })
}

//6.2 取消不喜欢
function removeDisLikes(target) {
    /* 参数是文章id:直接在路径后面写(id作为路径一部分)
    格式： url/id
    */
    return instance({
        url: `/v1_0/article/dislikes/${target}`,
        method: 'delete'
    })
}

// 搜索推荐词列表
function getSuggestion(q) {
    return instance({
        url: "/v1_0/suggestion",
        method: "get",
        params: { q }
    })
}

// 搜索结果列表
function getSearchList({ page, q }) {
    return instance({
        url: "/v1_0/search",
        method: 'get',
        params: {
            per_page: 10,
            page,
            q
        }
    })
}

export {
    getSearchList,
    removeDisLikes,
    addDisLikes,
    getChannelList,
    getArticleList,
    getArticleInfo,
    addFlowing,
    delFlowing,
    addLikings,
    delLikings,
    getSuggestion
}


